/**
 * Created by sun on 2016/8/4.
 */
define(function (require) {
    var app = require('/../js/app');
    require('ui-table');


    app.useModule("ui.table");
    var toastr =require('toastr');
    var datepicker = require('datepicker');
    app.controller('feeCtrl', ['$scope','$http','$filter' ,function ($scope, $http,$filter) {

        $scope.orderParams = {
            url: "/sys/fee/list"
        };
        datepicker($scope);
        $scope.select2Options = {
            minimumResultsForSearch: Infinity //不出现搜索框
        };

        //总览
        $scope.total=function(parm) {
            $http({
                method: 'POST',
                url: "/sys/fee/statCount",
                data:parm,
            }).success(function(data) {
                $scope.stat=data;
            }).error(function(data) {

            });
        };
        $scope.total();


        //全局查询
        $scope.search = function() {
            $scope.ctrlScope.itemsearch.beginDateTime=$scope.ctrlScope.itemsearch.beginDateTimex;
            $scope.ctrlScope.itemsearch.endDateTime= $scope.ctrlScope.itemsearch.endDateTimex;
            $scope.ctrlScope.itemsearch.beginDateTime=$filter('date')($scope.ctrlScope.itemsearch.beginDateTime,'yyyy-MM-dd');
            $scope.ctrlScope.itemsearch.endDateTime=$filter('date')($scope.ctrlScope.itemsearch.endDateTime,'yyyy-MM-dd');
            //表格查询参数设置
            $scope.orderParams.ajaxParam=$scope.ctrlScope.itemsearch;

            $scope.total($scope.ctrlScope.itemsearch);
            //表格刷新
            $scope.orderParams.reload();
        };

        //全局查询重置
        $scope.reset=function(){
            $scope.orderParams.ajaxParam={};
            $scope.ctrlScope.itemsearch={};
            $scope.orderParams.reload();
        };

        $scope.itemsearch={};
        //导出
        $scope.download=function(){
            var params=$scope.itemsearch;
            $http.post("/sys/fee/excelList",params)
                .success(function (data){
                    if(data.result=="success"){
                        window.open(data.file);
                    }else{
                        toastr.error("导出失败");
                    }
                }).error(function(data){
                });
        };

    }]);


});